<?php
require_once 'common.php';

try {
    $rows = SQLiteDB::getRows();

    $resouceList = [];
    foreach ($rows as $row) {
        if (!isset($resouceList[$row['ver']])) {
            $resouceList[$row['ver']] = [];
        }
        if (!isset($resouceList[$row['ver']][$row['user']])) {
            $resouceList[$row['ver']][$row['user']] = 0;
        }
        $resouceList[$row['ver']][$row['user']] += 1;
    }

    echo json_encode(['status' => 'success', 'data' => $resouceList]);
} catch (Exception $e) {
    echo json_encode(['status' => 'fail', 'message' => $e->getMessage()]);
}